using System;
using System.Collections.Generic;
using Main.Audio;
using Main.Details;
using Main.Dialogue;
using UnityEngine;

namespace Main.Event
{
    public static class MainEventSystem
    {
        public static event Action<InventoryLocation, List<InventoryItem>> UpdateInventoryUI;

        public static void CallUpdateInventoryUI(InventoryLocation location, List<InventoryItem> inventoryList)
        {
            UpdateInventoryUI?.Invoke(location, inventoryList);
        }

        /// <summary>
        /// 场景加载完成事件
        /// </summary>
        public static event Action LoadSceneFinish;
        internal static void CallLoadSceneFinish()
        {
            LoadSceneFinish?.Invoke();
        }

        /// <summary>
        /// 系统初始化
        /// </summary>
        public static event Action InitFinish;

        internal static void CallInitFinish()
        {
            InitFinish?.Invoke();
        }

        /// <summary>
        /// 物品选中事件
        /// </summary>
        public static event Action<ItemDetails, bool> ItemSelectEvent;
        internal static void CallItemSelectEvent(ItemDetails itemDetails, bool isSelected)
        {
            ItemSelectEvent?.Invoke(itemDetails, isSelected);
        }

        /// <summary>
        /// 当日时间变化事件
        /// </summary>
        public static event Action<int, int, int, int, Season> GameDayEvent;
        public static void CallGameDayEvent(int second, int minute, int hour, int day, Season season)
        {
            GameDayEvent?.Invoke(second, minute, hour, day, season);
        }

        /// <summary>
        /// 日期变化事件
        /// </summary>
        public static event Action<int, int, int, Season> GameDateEvent;
        public static void CallGameDateEvent(int day, int month, int year, Season season)
        {
            GameDateEvent?.Invoke(day, month, year, season);
        }

        /// <summary>
        /// 场景变化事件
        /// </summary>
        public static event Action<string, Vector3> TransitionEvent;
        public static void CallTransitionEvent(string sceneName, Vector3 position)
        {
            TransitionEvent?.Invoke(sceneName, position);
        }

        /// <summary>
        /// 场景加载前后事件
        /// </summary>
        public static event Action BeforeLoadSceneEvent;
        public static event Action AfterLoadSceneEvent;
        public static void CallBeforeLoadSceneEvent()
        {
            BeforeLoadSceneEvent?.Invoke();
        }
        public static void CallAfterLoadSceneEvent()
        {
            AfterLoadSceneEvent?.Invoke();
        }


        /// <summary>
        /// 切换场景后人物移动到指定坐标
        /// </summary>
        public static event Action<Vector3> MoveToPosition;
        public static void CallMoveToPosition(Vector3 position)
        {
            MoveToPosition?.Invoke(position);
        }


        /// <summary>
        /// 在有效范围内鼠标点击事件
        /// </summary>
        public static Action<Vector3, ItemDetails> MouseClickedEvent;
        internal static void CallMouseClickedEvent(Vector3 mouseWorldPos, ItemDetails currentItem)
        {
            MouseClickedEvent?.Invoke(mouseWorldPos, currentItem);
        }

        /// <summary>
        /// 动画执行完成后事件
        /// </summary>
        public static Action<Vector3, ItemDetails> ExecuteActionAfterAnimation;
        public static void CallExecuteActionAfterAnimation(Vector3 mouseWorldPos, ItemDetails currentItem)
        {
            ExecuteActionAfterAnimation?.Invoke(mouseWorldPos, currentItem);
        }


        /// <summary>
        /// 生成物品事件
        /// </summary>
        public static Action<int, Vector3> InstantiateItemEvent;
        public static void CallInstantiateItemEvent(int itemID, Vector3 position)
        {
            InstantiateItemEvent?.Invoke(itemID, position);
        }

        /// <summary>
        /// 丢弃物品事件
        /// </summary>
        public static Action<int, Vector3, ItemType> DropItemEvent;
        public static void CallDropItemEvent(int itemID, Vector3 position, ItemType itemType)
        {
            DropItemEvent?.Invoke(itemID, position, itemType);
        }

        /// <summary>
        /// 种植种子事件
        /// </summary>
        public static Action<int, TileDetails> PlantSeedEvent;
        public static void CallPlantSeedEvent(int itemID, TileDetails tileDetails)
        {
            PlantSeedEvent?.Invoke(itemID, tileDetails);
        }


        /// <summary>
        /// 在玩家当前坐标执行收割事件
        /// </summary>
        public static Action<int> HarvestAtPlayerPositionEvent;
        public static void CallHarvestAtPlayerPosition(int itemID)
        {
            HarvestAtPlayerPositionEvent?.Invoke(itemID);
        }

        /// <summary>
        /// 刷新网格地图事件
        /// </summary>
        public static Action RefreshMapEvent;
        public static void CallRefreshMapEvent()
        {
            RefreshMapEvent?.Invoke();
        }

        /// <summary>
        /// 指定位置生成例子效果
        /// </summary>
        public static Action<ParticleEffectType, Vector3> ParticleEffectEvent;
        public static void CallParticleEffectEvent(ParticleEffectType particleEffectType, Vector3 position)
        {
            ParticleEffectEvent?.Invoke(particleEffectType, position);
        }

        /// <summary>
        /// 生成种子事件
        /// </summary>
        public static Action GenerateCropEvent;
        public static void CallGenerateCropEvent()
        {
            GenerateCropEvent?.Invoke();
        }

        /// <summary>
        /// 开始对话时事件
        /// </summary>
        public static event Action<DialoguePiece> ShowDialogueEvent;
        public static void CallShowDialogueEvent(DialoguePiece dialoguePiece)
        {
            ShowDialogueEvent?.Invoke(dialoguePiece);
        }

        /// <summary>
        /// 打开背包的方法 (商店, 箱子)
        /// </summary>
        public static event Action<SlotType, InventoryBag_SO> BaseBagOpenEvent;
        public static void CallBaseBagOpenEvent(SlotType slotType, InventoryBag_SO inventoryBag)
        {
            BaseBagOpenEvent?.Invoke(slotType, inventoryBag);
        }

        /// <summary>
        /// 关闭背包的方法 (商店, 箱子)
        /// </summary>
        public static event Action<SlotType, InventoryBag_SO> BaseBagCloseEvent;
        public static void CallBaseBagCloseEvent(SlotType slotType, InventoryBag_SO inventoryBag)
        {
            BaseBagCloseEvent?.Invoke(slotType, inventoryBag);
        }

        /// <summary>
        /// 更新游戏状态
        /// </summary>
        public static event Action<GameState> UpdateGameStateEvent;
        public static void CallUpdateGameStateEvent(GameState gameState)
        {
            UpdateGameStateEvent?.Invoke(gameState);
        }

        /// <summary>
        /// 显示交易界面
        /// </summary>
        public static event Action<ItemDetails, bool> ShowTradeUIEvent;
        public static void CallShowTradeUI(ItemDetails itemDetails, bool isSell)
        {
            ShowTradeUIEvent?.Invoke(itemDetails, isSell);
        }

        /// <summary>
        /// 在地图上创建家具的方法, 传入蓝图家具id
        /// </summary>
        public static event Action<Vector3, int> BuildFurnitureEvent;
        public static void CallBuildFurniture(Vector3 mouseWorldPosition, int id)
        {
            BuildFurnitureEvent?.Invoke(mouseWorldPosition, id);
        }


        public static event Action<Season, LightShift, float> LightShiftChangEvent;
        public static void CallLightShiftChange(Season season, LightShift lightShift, float time)
        {
            LightShiftChangEvent?.Invoke(season, lightShift, time);
        }

        /// <summary>
        /// 播放特效声音
        /// </summary>
        public static event Action<SoundDetails> InitSoundEffect;
        public static void CallInitSoundEffect(SoundDetails soundDetails)
        {
            InitSoundEffect?.Invoke(soundDetails);
        }

        /// <summary>
        /// 根据音乐名称播放对应音乐clip
        /// </summary>
        public static event Action<SoundName> PlaySoundEvent;
        public static void CallPlaySoundEvent(SoundName soundName)
        {
            PlaySoundEvent?.Invoke(soundName);
        }

        /// <summary>
        /// 开始新的游戏
        /// </summary>
        public static event Action<int> StartNewGameEvent;
        public static void CallStartNewGameEvent(int index)
        {
            StartNewGameEvent?.Invoke(index);
        }
    }
}